﻿using WebSoftSeo.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace WebSoftSeo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {

        public void RegisterRoutes(RouteCollection routes)
        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                   name: "News",
                   url: "News/{title}-{id}",
                   defaults: new { controller = "News", action = "Detail", id = UrlParameter.Optional }
                );
            routes.MapRoute(
                name: "Service",
                url: "Service/{title}-{id}",
                defaults: new { controller = "Service", action = "Detail", id = UrlParameter.Optional }
             );
            routes.MapRoute(
                name: "Blog",
                url: "Blog/{title}-{id}",
                defaults: new { controller = "Blog", action = "Detail", id = UrlParameter.Optional }
             );
            routes.MapRoute(
               name: "BlogMonthFilter",
               url: "Blog/{month}/{year}",
               defaults: new { controller = "Blog", action = "MonthFilter", id = UrlParameter.Optional }
            );
            routes.MapRoute(
               name: "BlogMonthFilterPage",
               url: "Blog/{month}/{year}/{page}",
               defaults: new { controller = "Blog", action = "MonthFilter", id = UrlParameter.Optional }
            );
            //routes.MapRoute(
            //   name: "BlogCategory",
            //   url: "Blog/{CategoryName}/{id}",
            //   defaults: new { controller = "Blog", action = "Category", id = UrlParameter.Optional }
            //);

          
           

            routes.MapRoute(
                   name: "category",
                   url: "{title}",
                   defaults: new { controller = "Product", action = "ProductCategory", id = UrlParameter.Optional }
                );
            

            routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            ControllerBuilder.Current.DefaultNamespaces.Add("WebSoftSeo.Controllers");
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //AuthConfig.RegisterAuth();

            RegisterRoutes(RouteTable.Routes);
        }
        //protected void Application_Error()
        //{

        //    if (Context.IsCustomErrorEnabled)
        //        ShowCustomErrorPage(Server.GetLastError());

        //}
        //private void ShowCustomErrorPage(Exception exception)
        //{
        //    var httpException = exception as HttpException ?? new HttpException(500, "Internal Server Error", exception);

        //    Response.Clear();
        //    var routeData = new RouteData();
        //    routeData.Values.Add("controller", "Error");
        //    routeData.Values.Add("fromAppErrorEvent", true);

        //    switch (httpException.GetHttpCode())
        //    {
        //        case 403:
        //            routeData.Values.Add("action", "Unknown");
        //            break;

        //        case 404:
        //            routeData.Values.Add("action", "NotFound");
        //            break;

        //        case 500:
        //            routeData.Values.Add("action", "ServerError500");
        //            break;

        //        default:
        //            routeData.Values.Add("action", "Index");
        //            routeData.Values.Add("httpStatusCode", httpException.GetHttpCode());
        //            break;
        //    }

        //    Server.ClearError();

        //    IController controller = new ErrorController();
        //    controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
        //}
    }
}